local sk__shangjian = fk.CreateSkill {

  name = "sk__shangjian",

  tags = { Skill.Compulsory, },

}



sk__shangjian:addEffect(fk.EventPhaseStart, {
  name = "sk__shangjian",
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    if target == player and player.phase == Player.Discard then
      return player:hasSkill(sk__shangjian.name) and player:getHandcardNum() > player:getMaxCards() and
          #player.room.alive_players > 1
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local n = player:getHandcardNum() - player:getMaxCards()
    room:setPlayerMark(player, "sk__shangjian-phase", n)
    room:askToYiji(player,{
      targets=room:getOtherPlayers(player),
      cards=player:getCardIds("h"),
      min_num=n,
      max_num=n,
      skill_name=sk__shangjian.name,
      prompt="#sk__shangjian-give:::" .. n
    })
  end,
})
sk__shangjian:addEffect(fk.EventPhaseEnd, {
  name = "sk__shangjian",
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    if target == player and player.phase == Player.Discard then
      return player:getMark("sk__shangjian-phase") > 0
    end
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(player:getMark("sk__shangjian-phase"), sk__shangjian.name)
  end,
})

return sk__shangjian
